package com.word.app.mapper;

import com.word.app.pojo.NormWord;
import com.word.app.pojo.dto.BaseRemReq;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
* @author 311
* @description 针对表【normWord】的数据库操作Mapper
* @createDate 2022-06-16 12:13:09
* @Entity com.word.app.pojo.NormWord
*/
public interface NormWordMapper extends BaseMapper<NormWord> {
    
    @Select("SELECT a.* FROM normWord a JOIN remember b ON a.id=b.id where b.USER${uid}=#{remembered}")
    List<NormWord> queryRemember(String uid, boolean remembered);

    // @Select("SELECT a.* FROM normWord a JOIN remember b ON a.id=b.id where b.USER${uid}=#{remembered}")
    // IPage<NormWord> queryRememberByPage(Page<NormWord>page, NormWordRem word);
    IPage<NormWord> queryRememberByPage(Page<NormWord>page, BaseRemReq<NormWord> req);

    // @Update("update remember SET USER${uid}=#{remembered} WHERE id IN ${idxes}")
    // void updateRemember(String uid, String idxes, boolean remembered);
    void updateRemember(BaseRemReq<String> req);

    // @Select("SELECT a.* FROM normWord a JOIN remember b ON a.id=b.id where b.${uid}=1")
    List<NormWord> testQuery(NormWord word);

    @Update("ALTER TABLE remember ADD USER${uid} INT DEFAULT 0")
    void addRememberColumn(String uid);

    @Delete("ALTER TABLE remember DROP USER${uid}")
    void deleteRememberColumn(String uid);
    
    @Select("SHOW columns FROM remember LIKE #{uid}")
    Map isExistRememberColumn(String uid);
}




